move skytraq away from C style legacy time. (#1092)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Fri, 28 Apr 2023 21:09:21 +0000 (15:09 -0600)
committerGitHub <noreply@github.com>
Fri, 28 Apr 2023 21:09:21 +0000 (15:09 -0600)
Co-authored-by: Robert Lipe <robertlipe@users.noreply.github.com>
skytraq.cc
skytraq.h

index d5b791e7f9cfdb65df9ff8bbdeec170d933dd9e9..a228e6e65e38dc595ff6addba7e5f590bf75c929 100644 (file)
@@ -29,7 +29,6 @@
 #include <cstdio>          // for sscanf, snprintf, vprintf, SEEK_SET
 #include <cstdlib>         // for free
 #include <cstring>         // for memset
-#include <ctime>           // for time, time_t
 
 #include <QByteArray>      // for QByteArray
 #include <QChar>           // for QChar
@@ -502,8 +501,8 @@ unsigned int SkytraqBase::me_read32(const unsigned char* p)
   return ((unsigned)be_read16(p+2) << 16) | ((unsigned)be_read16(p));
 }
 
-time_t
-SkytraqBase::gpstime_to_timet(int week, int sec) const
+QDateTime
+SkytraqBase::gpstime_to_qdatetime(int week, int sec) const
 {
   /* Notes:
    *   * week rollover period can be specified using option
@@ -519,11 +518,12 @@ SkytraqBase::gpstime_to_timet(int week, int sec) const
    *   * overflow of sec into next week is allowed
    *     (i.e. sec >= 7*24*3600 = 604800 is allowed)
    */
-  time_t gps_timet = 315964800;     /* Jan 06 1980 0:00 UTC */
+  qint64 gps_timet = 315964800;     /* Jan 06 1980 0:00 UTC */
 
   int week_rollover = xstrtoi(opt_gps_week_rollover, nullptr, 10);
   if (week_rollover < 0) {
-    int current_week = (time(nullptr)-gps_timet)/(7*SECONDS_PER_DAY);
+    int current_week = (QDateTime::currentSecsSinceEpoch() - gps_timet)/
+                       (7*SECONDS_PER_DAY);
     week_rollover = current_week/1024 - (week > current_week%1024 ? 1 : 0);
   }
   gps_timet += (week+week_rollover*1024)*7*SECONDS_PER_DAY + sec;
@@ -531,7 +531,7 @@ SkytraqBase::gpstime_to_timet(int week, int sec) const
   int override = xstrtoi(opt_gps_utc_offset, nullptr, 10);
   if (override) {
     gps_timet -= override;
-    return gps_timet;
+    return QDateTime::fromSecsSinceEpoch(gps_timet);
   }
 
   /* leap second compensation: */
@@ -554,7 +554,7 @@ SkytraqBase::gpstime_to_timet(int week, int sec) const
   // Future: Consult http://maia.usno.navy.mil/ser7/tai-utc.dat
   // use http://www.stevegs.com/utils/jd_calc/ for Julian to UNIX sec
 
-  return gps_timet;     /* returns UTC time */
+  return QDateTime::fromSecsSinceEpoch(gps_timet);     /* returns UTC time */
 }
 
 void
@@ -612,7 +612,7 @@ SkytraqBase::make_trackpoint(struct read_state* st, double lat, double lon, doub
   wpt->latitude       = lat;
   wpt->longitude      = lon;
   wpt->altitude       = alt;
-  wpt->SetCreationTime(gpstime_to_timet(st->gps_week, st->gps_sec));
+  wpt->SetCreationTime(gpstime_to_qdatetime(st->gps_week, st->gps_sec));
 
   return wpt;
 }
index d7d6fe76b33651f0af33f170baf76c24f9ce4c57..89c7c4bd43fb303c4076305438efdb460ce8d4b3 100644 (file)
--- a/skytraq.h
+++ b/skytraq.h
 #ifndef SKYTRAQ_H_INCLUDED_
 #define SKYTRAQ_H_INCLUDED_
 
-#include <QString>   // for QString
-#include <QVector>   // for QVector
+#include <QDateTime>  // for QDateTime
+#include <QString>    // for QString
+#include <QVector>    // for QVector
 
-#include <cstdint>   // for uint8_t, int32_t, uint32_t, uint16_t, int16_t
-#include <ctime>     // for time_t
+#include <cstdint>    // for uint8_t, int32_t, uint32_t, uint16_t, int16_t
 
-#include "defs.h"    // for arglist_t, ARGTYPE_INT, ff_cap, ARG_NOMINMAX, ARGTYPE_STRING, ff_cap_read, ARGTYPE_BOOL, ff_cap_none, ff_type, ARGTYPE_OUTFILE, ff_type_serial, Waypoint, ff_type_file, route_head
-#include "format.h"  // for Format
-#include "gbfile.h"  // for gbfile
+#include "defs.h"
+#include "format.h"   // for Format
+#include "gbfile.h"   // for gbfile
 
 
 class SkytraqBase
@@ -128,7 +128,7 @@ protected:
   int skytraq_configure_logging() const;
   int skytraq_get_log_buffer_status(uint32_t* log_wr_ptr, uint16_t* sectors_free, uint16_t* sectors_total) const;
   static unsigned int me_read32(const unsigned char* p);
-  time_t gpstime_to_timet(int week, int sec) const;
+  QDateTime gpstime_to_qdatetime(int week, int sec) const;
   static void ECEF_to_LLA(double x, double y, long int z, double* lat, double* lon, double* alt);
   static void state_init(read_state* pst);
   Waypoint* make_trackpoint(read_state* st, double lat, double lon, double alt) const;